<template>
    <Modal v-model="modal.show" width="450" :title="modal.title">
        <Form ref="form" :model="formItem" :rules="ruleValidate" :label-width="150">
            <FormItem label="病种编码" prop="disease_Code"><Input v-model="formItem.disease_Code" placeholder=""
                    style="width: 200px" />
            </FormItem>
            <FormItem label="病种类型" prop="disease_Type"><Input v-model="formItem.disease_Type" placeholder=""
                    style="width: 200px" />
            </FormItem>
            <FormItem label="主要诊断编码" prop="diag_Code"><Input v-model="formItem.diag_Code" placeholder=""
                    style="width: 200px" />
            </FormItem>
            <FormItem label="主要诊断名称" prop="diag_Name"><Input v-model="formItem.diag_Name" placeholder=""
                    style="width: 200px" />
            </FormItem>
            <FormItem label="主要操作编码" prop="oper_Code"><Input v-model="formItem.oper_Code" placeholder=""
                    style="width: 200px" />
            </FormItem>
            <FormItem label="主要操作名称" prop="oper_Name"><Input v-model="formItem.oper_Name" placeholder=""
                    style="width: 200px" />
            </FormItem>
            <FormItem label="相关操作代码" prop="other_Code"><Input v-model="formItem.other_COde" placeholder=""
                    style="width: 200px" />
            </FormItem>
            <FormItem label="相关操作名称" prop="other_Name"><Input v-model="formItem.other_Name" placeholder=""
                    style="width: 200px" />
            </FormItem>
            <FormItem label="病种分值" prop="score">
                <InputNumber v-model="formItem.score" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="职工点值" prop="zgdz">
                <InputNumber v-model="formItem.zgdz" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="居民点值" prop="jmdz">
                <InputNumber v-model="formItem.jmdz" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="职工付费标准" prop="zgffbz">
                <InputNumber v-model="formItem.zgffbz" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="居民付费标准" prop="jmffbz">
                <InputNumber v-model="formItem.jmffbz" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="例均费用" prop="ljfy">
                <InputNumber v-model="formItem.ljfy" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="住院天数标杆值(天)" prop="zytsbgz">
                <InputNumber v-model="formItem.zytsbgz" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="高倍率" prop="highMag">
                <InputNumber v-model="formItem.highMag" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="低倍率" prop="lowMag">
                <InputNumber v-model="formItem.lowMag" :min="0" placeholder="" style="width: 200px" />
            </FormItem>
            <FormItem label="特殊标签" prop="specialFlag"><Input v-model="formItem.specialFlag" placeholder=""
                    style="width: 200px" />
            </FormItem>
        </Form>
        <template #footer>
            <div>
                <Button type="text" @click="modal.show = false">取消</Button>
                <Button type="primary" @click="handleOk">确定</Button>
            </div>
        </template>
    </Modal>
</template>
<script setup>
import http from '@/util/http'
import _ from 'lodash'
let { proxy } = getCurrentInstance()
const emit = defineEmits(['initList'])
let modal = reactive({ show: false, title: '' })
const form = ref()

let formItem = reactive({
    disease_Code: '',
    disease_Type: '',
    diag_Code: '',
    diag_Name: '',
    oper_Code: '',
    oper_Name: '',
    other_Code: '',
    other_Name: '',
    score: 0,
    zgdz: 0,
    jmdz: 0,
    zgffbz: 0,
    jmffbz: 0,
    zytsbgz: 0,
    ljfy: 0,
    highMag: 0,
    lowMag: 0,
    specialFlag: '',
})

const show = (type, data) => {
    form.value.resetFields()
    modal.show = true
    formItem.paraID = ''
    if (type == 1) {
        modal.title = '添加'
    } else {
        var clone = _.cloneDeep(data)
        formItem = clone
        modal.title = '编辑'
    }
}
const validateNum = (rule, value, callback) => {
    if (value === '' || value === null) {
        callback(new Error('请输入值'))
    } else {
        callback()
    }
}

const ruleValidate = {
    disease_code: [{ required: true, message: '请输入', trigger: 'blur' }],
    disease_type: [{ required: true, message: '请输入', trigger: 'blur' }],
    diag_code: [{ required: true, message: '请输入', trigger: 'blur' }],
    diag_name: [{ required: true, message: '请输入', trigger: 'blur' }],
    oper_code: [{ required: true, message: '请输入', trigger: 'blur' }],
    oper_name: [{ required: true, message: '请输入', trigger: 'blur' }],
    other_code: [{ required: true, message: '请输入', trigger: 'blur' }],
    other_name: [{ required: true, message: '请输入', trigger: 'blur' }],
    score: [{ required: true, validator: validateNum, trigger: 'blur' }],
    zgdz: [{ required: true, validator: validateNum, trigger: 'blur' }],
    jmdz: [{ required: true, validator: validateNum, trigger: 'blur' }],
    zgffbz: [{ required: true, validator: validateNum, trigger: 'blur' }],
    jmffbz: [{ required: true, validator: validateNum, trigger: 'blur' }],
    ljfy: [{ required: true, validator: validateNum, trigger: 'blur' }],
    zytsbgz: [{ required: true, validator: validateNum, trigger: 'blur' }],
    highMag: [{ required: true, validator: validateNum, trigger: 'blur' }],
    lowMag: [{ required: true, validator: validateNum, trigger: 'blur' }],
    specialFlag: [{ required: true, message: '请输入', trigger: 'blur' }],
}

const handleOk = () => {
    form.value.validate((valid) => {
        if (valid) {
            http.post('/Basic/DIPPara/AddOrUpdate', toRaw(formItem), (response) => {
                if (response.data.flag) {
                    emit('initList')
                    proxy.$Message.success(response.data.msg)
                    modal.show = false
                } else {
                    proxy.$Message.error(response.data.msg)
                }
            })
        } else {
            return false
        }
    })
}

defineExpose({
    show,
})
</script>